#ifndef POWERMETER_H
#define POWERMETER_H

#include <QObject>
#include <QDebug>
#include <QJsonObject>

#define POWER_LEVEL_100W      0
#define POWER_LEVEL_200W      1
#define POWER_LEVEL_400W      2
#define POWER_LEVEL_800W      3
#define POWER_LEVEL_1000W     4
#define POWER_LEVEL_1500W     5
#define POWER_LEVEL_2000W     6
#define POWER_LEVEL_3000W     7
#define POWER_LEVEL_5000W     8
#define POWER_LEVEL_8000W     9
#define POWER_LEVEL_10000W    10
#define POWER_LEVEL_12000W    11
#define POWER_LEVEL_15000W    12

class PowerMeter : public QObject
{
  Q_OBJECT
public:
  explicit PowerMeter(QObject *parent = 0);

  /*! \brief Set the type of pickup the Power Meter is using
   *  \param type The Power Meter type */
  void setPickupType(quint8 type);
  /*! \brief Set the alarm level of the forward power
   *  \param value The alarm level */
  void setAlarmLevelFWDPower(quint16 value);
  /*! \brief Set the alarm level of the reflected power
   *  \param value The alarm level */
  void setAlarmLevelREFPower(quint16 value);
  /*! \brief Set the alarm level of the VSWR
   *  \param value The alarm level */
  void setAlarmLevelVSWR(float value);
  /*! \brief Set the data poll interval of how often we ask the
   *         power meter module about the information
   *  \param value The alarm level */
  void setDataPollInterval(quint16 value);

  /*! \brief Get the current forward power
   *  \return The current forward power value */
  quint16 getCurrentFWDPower();
  /*! \brief Get the current reflected power
   *  \return The current reflected power value */
  quint16 getCurrentREFPower();
  /*! \brief Get the current VSWR value
   *  \return The current VSWR value */
  float getCurrentVSWR();
  /*! \brief Get the Power Meter pickup type
   *  \return The pickup type */
  quint8 getPickupType();
  /*! \brief Get the alarm level for the forward power
   *  \return The forward power alarm value */
  quint16 getAlarmLevelFWDPower();
  /*! \brief Get the alarm level for the reflected power
   *  \return The forward power alarm value */
  quint16 getAlarmLevelREFPower();
  /*! \brief Get the alarm level for the VSWR
   *  \return The VSWR alarm value */
  float getAlarmLevelVSWR();
  /*! \brief Get the data poll interval of how often we retrieve
   *         data from the power meter hardware module
   *  \return The data poll interval */
  quint16 getDataPollInterval();

  /*! \brief Get the data from the class and put it in a JSON object
      \param reference to the JSON object */
  void getData(QJsonObject &json);

  /*! \brief Put data from a JSON object into the class
      \param reference to the JSON object */
  void putData(const QJsonObject &json);

private:
  //! The current forward value
  quint16 currentFWDPower;
  //! The current reflected value
  quint16 currentREFPower;
  //!The current VSWR value
  float currentVSWR;

  //! The type of pickup we are using, which power level it is
  quint8 pickupPowerLevel;
  //! Max forward power that we allow
  quint16 alarmLevelFWDPower;
  //! Max reflected power that we allow
  quint16 alarmLevelREFPower;
  //! Alarm level for the VSWR
  float alarmLevelVSWR;

  //! The poll interval which we retrieve the data from the power meter module
  quint16 dataPollInterval;
signals:
  void valueChanged();
public slots:
  /*! \brief Set the current forward power value
   *  \param value The current forward power */
  void setCurrentFWDPower(quint16 value);
  /*! \brief Set the current reflected power value
   *  \param value The current reflected power */
  void setCurrentREFPower(quint16 value);
  /*! \brief Set the current VSWR value
   *  \param value The current VSWR */
  void setCurrentVSWR(float value);
  /*! \brief A timer for the power meter */
  void powerMeterEvent();
};

#endif // POWERMETER_H
